package com.yswy.domain.vo.dto;

import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

public class BaseFilter implements Serializable {
    static final Integer DEFAULT_PAGE_INDEX = 1;
    static final Integer DEFAULT_PAGE_SIZE = 10;

    /** 当前页码，默认第一页  */
    private Integer pageNum;
    /** 每页显示条数， 默认10条  */
    private Integer pageSize;

    @ApiModelProperty("搜索名字")
    private String searchMsg ;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("开始时间")
    private Date startTime ;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("结束时间")
    private Date endTime ;

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageNum() {
        this.pageNum = (pageNum == null || pageNum < 1) ? DEFAULT_PAGE_INDEX : pageNum;
        return pageNum;
    }

    public Integer getPageSize() {
        this.pageSize = (pageSize == null || pageSize < 1) ? DEFAULT_PAGE_SIZE : pageSize;
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }


    public String getSearchMsg() {
        return searchMsg;
    }
    public void setSearchMsg(String searchMsg) {
        this.searchMsg = searchMsg;
    }


    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getEndTime() {
        return null == endTime ? null : addTime(endTime);
    }
    private Date addTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, 1);
        return calendar.getTime();
    }
}
